$.config = {
    routerFilter: function($link) {
        var href = $($link).attr('href');
        if ($link.hasClass('redirect') && href != '') {
            $.toast('跳转中...');
            return false;
        }
        if ($link.hasClass('external')) {
            $.showIndicator();
        }
        return true;
    }
};
$(function () {
    'use strict';
    $(document).on('pageInit', '.page', function(e, id, page) {
        if ($('.redirect').length) {
            var href = $('.redirect').attr('href');
            if (href != '') {
                setTimeout(function(){
                    $.showIndicator();
                    window.location.href = href;
                }, 2000);
            }
        }
    });
    $(document).on('pageInit', '.superpage_sign', function(e, id, page) {
        /*wx.ready(function(){
            wx.hideOptionMenu();
        });*/

        //签到规则
        $('.sign_rule').click(function () {
            $.popup('.sign_popup');
        });

        //签到
        $('.btn_3d.btn_3d_up').click(function () {
            if ($(this).hasClass('btn_3d_down')) {
                return false;
            }
            $.showPreloader('签到中...');
            $(this).removeClass('btn_3d_up').addClass('btn_3d_down');
            $(this).parent().submit();
        });

        //初始化签到提示
        if (typeof(window.sysinfo._sign.today_rank) != 'undefined' && window.sysinfo._sign.dialog==1) {
            var timer = setTimeout(function() {
                $.closeModal();
            }, 2000);
            var txt = '签到成功<span style="color: #e43600">+'+window.sysinfo._sign.reward+'</span>';
            if (window.sysinfo._sign.extra_reward != '') {
                var extra_reward = window.sysinfo._sign.extra_reward;
                if (typeof(extra_reward.first) != 'undefined') {
                    txt += '<br>首次签到奖励<span style="color: #e43600">+'+extra_reward.first+'</span>';
                } else if (typeof(extra_reward.continue) != 'undefined') {
                    txt += '<br>连续签到奖励<span style="color: #e43600">+'+extra_reward.continue+'</span>';
                }
            }
            $.modal({
                title: '<img src="/addons/superman_sign/template/mobile/images/158.gif">',
                text: txt,
                buttons: [
                    {
                        text: '2秒后自动关闭',
                        onClick: function() {
                            clearTimeout(timer);
                        }
                    }
                ]
            });
        }

        //切换排行榜
        $('.rank_link').click(function(){
            $.showIndicator();
        });

        if ($('#creditmall_order').html() != null) {
            setInterval(function(){
                $('#creditmall_order').animate({
                    marginTop: "-2rem"
                }, 500, function() {
                    $(this).css({ marginTop: "0px" }).find("li:first").appendTo(this);
                });
            }, 5000);
        }
    });

    $.init();
});
